package br.com.locadora.cliente;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;

import br.com.locadora.endereco.Endereco;
import br.com.locadora.locacao.Locacao;

@Entity
@SequenceGenerator(name = "cliente_seq", sequenceName = "cliente_seq", allocationSize = 1, initialValue = 1)
public class Cliente implements Serializable {

	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(generator = "cliente_seq")
	private Integer cliCodigo;

	@OneToOne
	@JoinColumn(name = "cliEndereco")
	private Endereco cliEndereco;

	@OneToMany(mappedBy = "locCliente")
	private List<Locacao> cliLocacao;

	private String cliNome;
	private String cliTelefone;
	private String cliCelular;
	private String cliEmail;

	public Integer getCliCodigo() {
		return cliCodigo;
	}

	public void setCliCodigo(Integer cliCodigo) {
		this.cliCodigo = cliCodigo;
	}

	public Endereco getCliEndereco() {
		return cliEndereco;
	}

	public void setCliEndereco(Endereco cliEndereco) {
		this.cliEndereco = cliEndereco;
	}

	public List<Locacao> getCliLocacao() {
		return cliLocacao;
	}

	public void setCliLocacao(List<Locacao> cliLocacao) {
		this.cliLocacao = cliLocacao;
	}

	public String getCliNome() {
		return cliNome;
	}

	public void setCliNome(String cliNome) {
		this.cliNome = cliNome;
	}

	public String getCliTelefone() {
		return cliTelefone;
	}

	public void setCliTelefone(String cliTelefone) {
		this.cliTelefone = cliTelefone;
	}

	public String getCliCelular() {
		return cliCelular;
	}

	public void setCliCelular(String cliCelular) {
		this.cliCelular = cliCelular;
	}

	public String getCliEmail() {
		return cliEmail;
	}

	public void setCliEmail(String cliEmail) {
		this.cliEmail = cliEmail;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((cliCelular == null) ? 0 : cliCelular.hashCode());
		result = prime * result
				+ ((cliCodigo == null) ? 0 : cliCodigo.hashCode());
		result = prime * result
				+ ((cliEmail == null) ? 0 : cliEmail.hashCode());
		result = prime * result
				+ ((cliLocacao == null) ? 0 : cliLocacao.hashCode());
		result = prime * result + ((cliNome == null) ? 0 : cliNome.hashCode());
		result = prime * result
				+ ((cliTelefone == null) ? 0 : cliTelefone.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Cliente other = (Cliente) obj;
		if (cliCelular == null) {
			if (other.cliCelular != null)
				return false;
		} else if (!cliCelular.equals(other.cliCelular))
			return false;
		if (cliCodigo == null) {
			if (other.cliCodigo != null)
				return false;
		} else if (!cliCodigo.equals(other.cliCodigo))
			return false;
		if (cliEmail == null) {
			if (other.cliEmail != null)
				return false;
		} else if (!cliEmail.equals(other.cliEmail))
			return false;
		if (cliLocacao == null) {
			if (other.cliLocacao != null)
				return false;
		} else if (!cliLocacao.equals(other.cliLocacao))
			return false;
		if (cliNome == null) {
			if (other.cliNome != null)
				return false;
		} else if (!cliNome.equals(other.cliNome))
			return false;
		if (cliTelefone == null) {
			if (other.cliTelefone != null)
				return false;
		} else if (!cliTelefone.equals(other.cliTelefone))
			return false;
		return true;
	}
}
